package controller

import (
	"hft/Database/admin"
	"hft/Http/Models/request"
	services "hft/Http/Services"
	utils "hft/Http/Utils"
	"hft/tools"

	"github.com/gin-gonic/gin"
)

type Disadvantage struct{}

func (*Disadvantage) CreateDisadvantage(c *gin.Context) {
	var status *admin.Disadvantage

	c.ShouldBindJSON(&status)

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.FailWithMessage("授权失败", c)
		return
	}

	err = services.DisadvantageService.CreateDisadvantage(status, claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*Disadvantage) EditDisadvantage(c *gin.Context) {

	var status *admin.Disadvantage

	c.ShouldBindJSON(&status)

	err := services.DisadvantageService.EditDisadvantage(status)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)
}

func (*Disadvantage) GetDisadvantageList(c *gin.Context) {

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.FailWithMessage("授权失败", c)
		return
	}

	list, err := services.DisadvantageService.GetDisadvantageList(claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.OkWithData(list, c)

}

func (*Disadvantage) Delete(c *gin.Context) {

	var IDS *request.IDS

	c.ShouldBindJSON(&IDS)

	claims, err := tools.GetClaims(c)

	if err != nil {
		utils.Fail(c)
		return
	}

	err = services.DisadvantageService.Delete(IDS.IDS, claims.BaseClaims)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

func (*Area) Delete(c *gin.Context) {

	var IDS *request.IDS

	c.ShouldBindJSON(&IDS)

	err := services.AreaService.Delete(IDS.IDS)

	if err != nil {
		utils.FailWithMessage(err.Error(), c)
		return
	}

	utils.Ok(c)

}

var DisadvantageController = new(Disadvantage)
